package QQ;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;


public class School {
    public static void main(String[] args) {
        // 创建学生对象
        Student student1 = new Student("张三", 1);
        Student student2 = new Student("李四", 2);
        Student student3 = new Student("王二", 3);
        Student student4 = new Student("张飞", 4);
        Student student5 = new Student("黑旋风", 5);

        // 创建小组对象并添加学生
        Group group1 = new Group("Group 1");
        group1.addStudent(student1);
        group1.addStudent(student2);

        Group group2 = new Group("Group 2");
        group2.addStudent(student3);
        group2.addStudent(student4);
        group2.addStudent(student5);

        // 创建班级对象并添加小组
        Class class1 = new Class("Class 1");
        class1.addGroup(group1);
        class1.addGroup(group2);

        // 打印班级信息
        System.out.println(class1);

        // 随机抽取小组和学生
        randomSelect(class1);
    }

    // 随机抽取小组和学生
    public static void randomSelect(Class class1) {
        Random random = new Random();

        // 随机抽取一个小组
        List<Group> groups = class1.getGroups();
        Group randomGroup = groups.get(random.nextInt(groups.size()));
        System.out.println("Randomly selected group: " + randomGroup.getGroupName());

        // 随机抽取小组中的一个学生
        List<Student> studentsInGroup = randomGroup.getStudents();
        Student randomStudentInGroup = studentsInGroup.get(random.nextInt(studentsInGroup.size()));
        System.out.println("Randomly selected student from group: " + randomStudentInGroup);

        // 随机从全班级抽取一个学生
        List<Student> allStudents = new ArrayList<>();
        for (Group group : groups) {
            allStudents.addAll(group.getStudents());
        }
        Student randomStudentInClass = allStudents.get(random.nextInt(allStudents.size()));
        System.out.println("Randomly selected student from class: " + randomStudentInClass);
    }

}
